const ua = typeof window !== 'undefined' ? window.navigator.userAgent : '';
const isOSX = (/OS X/).test(ua);
const isOpera = (/Opera/).test(ua);
const maybeFirefox = !(/like Gecko/).test(ua) && !isOpera;

let i;
export const output = {
    0: isOSX ? '<menu>' : '<UNK>',
    1: '<mouse 1>',
    2: '<mouse 2>',
    3: '<break>',
    4: '<mouse 3>',
    5: '<mouse 4>',
    6: '<mouse 5>',
    8: '<backspace>',
    9: '<tab>',
    12: '<clear>',
    13: '<enter>',
    16: '<shift>',
    17: '<control>',
    18: '<alt>',
    19: '<pause>',
    20: '<caps-lock>',
    21: '<ime-hangul>',
    23: '<ime-junja>',
    24: '<ime-final>',
    25: '<ime-kanji>',
    27: '<escape>',
    28: '<ime-convert>',
    29: '<ime-nonconvert>',
    30: '<ime-accept>',
    31: '<ime-mode-change>',
    32: '<space>',
    33: '<page-up>',
    34: '<page-down>',
    35: '<end>',
    36: '<home>',
    37: '<left>',
    38: '<up>',
    39: '<right>',
    40: '<down>',
    41: '<select>',
    42: '<print>',
    43: '<execute>',
    44: '<snapshot>',
    45: '<insert>',
    46: '<delete>',
    47: '<help>',
    91: '<meta>', // meta-left -- no one handles left and right properly, so we coerce into one.
    92: '<meta>', // meta-right
    93: isOSX ? '<meta>' : '<menu>', // chrome,opera,safari all report this for meta-right (osx mbp).
    95: '<sleep>',
    106: '<num-*>',
    107: '<num-+>',
    108: '<num-enter>',
    109: '<num-->',
    110: '<num-.>',
    111: '<num-/>',
    144: '<num-lock>',
    145: '<scroll-lock>',
    160: '<shift-left>',
    161: '<shift-right>',
    162: '<control-left>',
    163: '<control-right>',
    164: '<alt-left>',
    165: '<alt-right>',
    166: '<browser-back>',
    167: '<browser-forward>',
    168: '<browser-refresh>',
    169: '<browser-stop>',
    170: '<browser-search>',
    171: '<browser-favorites>',
    172: '<browser-home>',

    // ff/osx reports '<volume-mute>' for '-'
    173: isOSX && maybeFirefox ? '-' : '<volume-mute>',
    174: '<volume-down>',
    175: '<volume-up>',
    176: '<next-track>',
    177: '<prev-track>',
    178: '<stop>',
    179: '<play-pause>',
    180: '<launch-mail>',
    181: '<launch-media-select>',
    182: '<launch-app 1>',
    183: '<launch-app 2>',
    186: ';',
    187: '=',
    188: ',',
    189: '-',
    190: '.',
    191: '/',
    192: '`',
    219: '[',
    220: '\\',
    221: ']',
    222: '\'',
    223: '<meta>',
    224: '<meta>', // firefox reports meta here.
    226: '<alt-gr>',
    229: '<ime-process>',
    231: isOpera ? '`' : '<unicode>',
    246: '<attention>',
    247: '<crsel>',
    248: '<exsel>',
    249: '<erase-eof>',
    250: '<play>',
    251: '<zoom>',
    252: '<no-name>',
    253: '<pa-1>',
    254: '<clear>'
};

for (i = 58; i < 65; ++i)
{
    output[i] = String.fromCharCode(i);
}

// 0-9
for (i = 48; i < 58; ++i)
{
    output[i] = `${i - 48}`;
}

// A-Z
for (i = 65; i < 91; ++i)
{
    output[i] = String.fromCharCode(i);
}

// num0-9
for (i = 96; i < 106; ++i)
{
    output[i] = `<num-${i - 96}>`;
}

// F1-F24
for (i = 112; i < 136; ++i)
{
    output[i] = `F${i - 111}`;
}
